package com.alks.function.controller.chengKong;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.MinIoUtil;
import com.alks.entity.data.entity.YfStyleColorDetail;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.chengKong.*;
import com.alks.function.service.chengKong.GeneralMaterialsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@ApiRestController("/common")
@Api(tags = {
         "成控部-物料管理作业-成型材料建档"
        , "成控部-物料管理作业-公共材料定义"
        , "成控部-物料管理作业-研发型体建档"})
@Slf4j
public class GeneralMaterialsController {

    @Autowired
    private GeneralMaterialsService generalMaterialsService;

    @WebLogger
    @GetMapping("/getGeneralMaterialsList")
    @ApiOperation(value = "成型材料建档列表",tags = "成控部-物料管理作业-成型材料建档")
    public ResponseInfo getGeneralMaterialsList(){
        return generalMaterialsService.getGeneralMaterialsList();
    }

    @WebLogger
    @PostMapping("/getGeneralMaterialsAdd")
    @ApiOperation(value = "通用材料建档",tags = "成控部-物料管理作业-成型材料建档")
    public ResponseInfo getGeneralMaterialsAdd(@RequestBody CacheAddRequest request){
        return generalMaterialsService.getGeneralMaterialsAdd(request);
    }

    @WebLogger
    @PostMapping("/getMaterialQueryList")
    @ApiOperation(value = "材料查询列表",tags = "成控部-物料管理作业-成型材料建档")
    public ResponseInfo getMaterialQueryList(@RequestBody MaterialQueryRequest2 request){
        return generalMaterialsService.getMaterialQueryList(request);
    }

    @WebLogger
    @PutMapping("/getMaterialUpdate")
    @ApiOperation(value = "材料查询修改",tags = "成控部-物料管理作业-成型材料建档")
    public ResponseInfo getMaterialUpdate(@RequestBody YfMaterialUpdateRequest request){
        return generalMaterialsService.getMaterialUpdate(request);
    }

    @WebLogger
    @PostMapping("/getMaterialDel")
    @ApiOperation(value = "材料查询删除",tags = "成控部-物料管理作业-成型材料建档")
    public ResponseInfo getMaterialDel(@RequestParam String mtlNo){
        return generalMaterialsService.getMaterialDel(mtlNo);
    }

    @WebLogger
    @PostMapping("/getPublicMaterials")
    @ApiOperation(value = "正式材料列表明细",tags = "成控部-物料管理作业-公共材料定义")
    public ResponseInfo getPublicMaterials(@RequestBody CommonQueryRequest request){
        return generalMaterialsService.getPublicMaterials(request);
    }

    @WebLogger
    @PutMapping("/getPublicMaterialsUpdate")
    @ApiOperation(value = "正式材料列表修改",tags = "成控部-物料管理作业-公共材料定义")
    public ResponseInfo getPublicMaterialsUpdate(@RequestBody CommonUpdateRequest request){
        return generalMaterialsService.getPublicMaterialsUpdate(request);
    }

    @WebLogger
    @PostMapping("/getStyleAdd")
    @ApiOperation(value = "新增作业",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleAdd(@RequestBody Map<String,String> map){
        return  generalMaterialsService.getStyleAdd(map);
    }

    @WebLogger
    @PostMapping("/getStyleBasicAdd")
    @ApiOperation(value = "保存",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleBasicAdd(@RequestBody StyleAddRequest request){
        return generalMaterialsService.getStyleBasicAdd(request);
    }

    @WebLogger
    @PostMapping("/getStyleNumber")
    @ApiOperation(value = "取号码",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleNumber(@RequestBody Map<String,String> map){
        return generalMaterialsService.getStyleNumber(map);
    }

    @WebLogger
    @PostMapping("/getStyleNumberAdd")
    @ApiOperation(value = "取号码插入",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleNumberAdd(@RequestBody StyleNumberAddRequest request){
        return generalMaterialsService.getStyleNumberAdd(request);
    }

    @WebLogger
    @PostMapping("/getStyleBasicList")
    @ApiOperation(value = "基本制具资料查询",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleBasicList(@RequestBody StyleBasicRequest request){
        return generalMaterialsService.getStyleBasicList(request);
    }

    @WebLogger
    @GetMapping("/getStyleType")
    @ApiOperation(value = "制具资料查询",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleType(@RequestParam String styleNo){
        return generalMaterialsService.getStyleType(styleNo);
    }

    @WebLogger
    @PostMapping("/getStyleSizeList")
    @ApiOperation(value = "配码资料查询",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleSizeList(@RequestBody Map<String,String> map){
        return generalMaterialsService.getStyleSizeList(map);
    }

    @WebLogger
    @PostMapping("/getStylePhotoList")
    @ApiOperation(value = "型体配色资料查询",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStylePhotoList(@RequestBody Map<String,String> map){
        return generalMaterialsService.getStylePhotoList(map);
    }

    @WebLogger
    @PostMapping("/getStyleBasicCopyAdd")
    @ApiOperation(value = "复制",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleBasicCopyAdd(@RequestBody StyleAddRequest request){
        return generalMaterialsService.getStyleBasicCopyAdd(request);
    }

    @WebLogger
    @PostMapping("/getStyleBasicAllDel")
    @ApiOperation(value = "整单删除",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStyleBasicAllDel(@RequestBody Map<String,String> map){
        return generalMaterialsService.getStyleBasicAllDel(map);
    }

    @WebLogger
    @PostMapping("/getChangeOfOrderMaker")
    @ApiOperation(value = "制单员变更",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getChangeOfOrderMaker(@RequestBody Map<String,String> map){
        return generalMaterialsService.getChangeOfOrderMaker(map);
    }

    @WebLogger
    @PostMapping("/getInspect/{choose}")
    @ApiOperation(value = "0检验/1取消检验",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getInspect(@RequestBody List<String> styleNoList,@PathVariable("choose") Integer choose){
        return generalMaterialsService.getInspect(styleNoList,choose);
    }

    @PostMapping("/updateStylePhoto")
    @ApiOperation(value = "上传图片",tags = {"成控部-物料管理作业-研发型体建档"})
    @WebLogger
    public ResponseInfo updateStylePhoto(@RequestParam(value = "file") MultipartFile file, String photoPath) {
        return generalMaterialsService.updateStylePhoto(file,photoPath);
    }

    @Resource
    MinIoUtil minIoUtil;

    @WebLogger
    @ApiOperation(value = "图片下载",tags = {"成控部-物料管理作业-研发型体建档"})
    @GetMapping("/download")
    public void download(@RequestParam(name = "fileName") String fileName,
                         HttpServletResponse response){
        try {
            //对路径进行切割
            int index = fileName.indexOf("/photo");
            fileName = fileName.substring(index + "photo".length() + 1);
            minIoUtil.download("photo",fileName,response);
        }catch (Exception e){
            log.error("图片下载失败!");
            e.printStackTrace();
        }
    }

    @WebLogger
    @PostMapping("/getStylePhotoAdd")
    @ApiOperation(value = "型体配色资料添加",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStylePhotoAdd(@RequestBody YfStyleColorDetail styleColorDetail){
        return generalMaterialsService.getStylePhotoAdd(styleColorDetail);
    }

    @WebLogger
    @PostMapping("/getStylePhotoDel")
    @ApiOperation(value = "型体配色资料删除",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStylePhotoDel(@RequestBody YfStyleColorDetail styleColorDetail){
        return generalMaterialsService.getStylePhotoDel(styleColorDetail);
    }

    @WebLogger
    @PostMapping("/getStylePhotoUpdate")
    @ApiOperation(value = "型体配色资料修改",tags = "成控部-物料管理作业-研发型体建档")
    public ResponseInfo getStylePhotoUpdate(@RequestParam@ApiParam("修改前型体") String styleNo,
                                            @RequestParam@ApiParam("修改前颜色") String styleColor,
                                            @RequestBody YfStyleColorDetail styleColorDetail){
        return generalMaterialsService.getStylePhotoUpdate(styleNo,styleColor,styleColorDetail);
    }
}
